<style lang="less" scoped>

  .el-row {
    margin-bottom: 20px;
  }

  .el-col {
    border-radius: 4px;
  }

  .bg-purple-dark {
    background: #ffffff;
  }

  .grid-content {
    border-radius: 4px;
    min-height: 36px;
  }

  .el-form-item {
    margin: 0px 20px 15px 20px;
  }

  .f-bs1 {
    border: 1px solid #dfe6ec;
  }

  .el-collapse {
    border: 0px;
    .el-collapse-item {
      border: 1px solid #dfe6ec;
      margin-bottom: 10px;
      .el-collapse-item__header {
        font-weight: bold;
        .el-collapse-item__header__arrow {
          display: none;
        }
      }
      .el-collapse-item__content {
        padding-bottom: 0px;
      }
      .el-collapse-item__wrap {
        border-bottom: 0px;
      }
    }
  }

  label {
    width: 100px;
  }

  .el-form-item[data-v-7da61f17] {
    margin: 0 0 0 0
  }

  .f-mt10 {
    margin-top: 10px;
  }

  .f-ml20 {
    margin-left: 20px;
  }

  .f-mr20 {
    margin-right: 20px;
  }

  .f-mb10 {
    margin-bottom: 10px;
  }

  .f-tar {
    text-align: right;
  }

  .f-h30 {
    height: 30px;
  }

  .f-c-red {
    color: red;
  }

  .el-radio-group {
    width: 60%;
  }

  .el-radio-invoice {
    margin-right: 30px;
  }

  .f-color {
    color: #25baaf;
  }

  .el-textarea {
    width: 86%;
  }

  .f-mb {
    margin-bottom: 0;
  }

  .f-fr {
    float: right;
  }

  .f-fl {
    float: left;
  }

  .f-lh38 {
    line-height: 38px;
  }

  .el-select {
    width: 100%;
  }

  .f-w233 {
    width: 100%;
  }

  .el-form-item__label {
    width: 150px;
  }

  .el-date-editor.el-input {
    width: 100%;
  }

  li {
    list-style-type: none;
  }

  .color-c8c8c8 {
    color: #c8c8c8;
  }

  .f-mt {
    margin-top: 0;
  }

  .width70 {
    width: 70%;
  }

  .width80 {
    width: 80%;
  }
  .width100 {
    width: 100%;
  }
</style>
<template>
  <section>
    <!--工具条-->
    <search-bar more-display>
      <el-row>
        <el-col :span="8">
          <el-form-item label="字典组">
            <el-input
                      v-model="searchCondition.LIKE_cnDictValName" placeholder="请输入字典组"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="代码">
            <el-input
                      v-model="searchCondition.EQ_dictCode" placeholder="请输入代码"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="字典组编码">
            <el-input
                      v-model="searchCondition.LIKE_dictType" placeholder="请输入字典组编码"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </search-bar>

    <!-- 操作 -->
    <el-col :span="24" style="margin-bottom: 10px">
      <el-button type="primary" @click="handleAdd">新增</el-button>
      <el-button type="primary" @click="myReset" style="float: right">重置</el-button>
      <el-button type="primary" @click="searchStmDict" style="float: right">查询</el-button>
    </el-col>

    <!--列表-->
    <el-table :data="tableData" highlight-current-row border @sort-change="sortChange" max-height="650"
              @selection-change="selsChange" v-loading="listLoading" style="width: 100%;">
      <el-table-column type="index" label="序号" width="80" >
      </el-table-column>
      <el-table-column prop="cnDictValName" width="200" label="字典组" >
      </el-table-column>
      <el-table-column prop="dictType" label="字典组编码" width="250" >
      </el-table-column>
      <el-table-column prop="dictCode" label="代码" width="150" >
      </el-table-column>
      <el-table-column prop="sort" label="排序" width="50" >
      </el-table-column>
      <el-table-column show-overflow-tooltip prop="remark" label="描述" >

      </el-table-column>

      <el-table-column fixed="right" label="操作" width="300" align="center">

        <template slot-scope="scope">
          <el-button  type="primary" @click="getEditBYId(scope.$index, scope.row)">编辑
          </el-button>
          <el-button type="danger"  @click="handleDel(scope.$index, scope.row)">删除</el-button>
          <el-button type="primary"  @click="getEditDetail(scope.$index, scope.row)">查看详情</el-button>
        </template>

      </el-table-column>
    </el-table>

    <!--工具条-->
    <el-col :span="24" class="toolbar">
      <el-pagination
        :current-page="currentPage"
        :page-size="pageSize"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total,sizes,prev, pager, next, jumper"
        :total="total" style="float: right">
      </el-pagination>
    </el-col>
    <!--新增数字字典 弹窗 -->
    <el-dialog :title="dialogTitle" size="tiny" :visible.sync="stmDictVisible" :close-on-click-modal="false">
      <el-form :model="stmDict" :rules="rules" label-width="110px" ref="stmDict">
        <el-row class="f-mt10 f-mb10">
          <el-col :span="24">
            <el-form-item label="字典组" class="width70" prop="cnDictValName">
              <el-input v-model="stmDict.cnDictValName" placeholder="请输入字典组"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row class="f-mt10 f-mb10">
          <el-col :span="24">
            <el-form-item label="字典组编码" class="width70" prop="dictType">
              <el-input v-model="stmDict.dictType" placeholder="请输入字典组编码 "></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row class="f-mt10 f-mb10">
          <el-col :span="24">
            <el-form-item label="代码" class="width70" prop="dictCode"
                          :rules="[{required: true,type:'number', message: '请输入代码', trigger: 'change'}]">
              <el-input type="number" v-model.number="stmDict.dictCode" placeholder="请输入代码"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row class="f-mt10 f-mb10">
          <el-col :span="24">
            <el-form-item label="排序" class="width70" prop="sort"
                          :rules="[{required: true,type:'number', message: '请输入排序', trigger: 'change'}]">
              <el-input type="number" v-model.number="stmDict.sort" placeholder="请输入排序"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row class="f-mt10 f-mb10">
          <el-col :span="24">
            <el-form-item label="描述">
              <el-input type="textarea" v-model="stmDict.remark" placeholder="请输入描述"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="stmDictVisible = false">取消</el-button>
        <el-button type="primary" @click.native="handleSubmit" :loading="submitLoading">提交</el-button>
      </div>
    </el-dialog>

    <!--数字字典查看详情弹窗 -->
    <el-dialog :title="addDialogTitle" size="large" :visible.sync="stmDictDetailVisible" :close-on-click-modal="false">
      <el-form :model="stmDict" :rules="rules" label-width="90px" ref="stmDict">
        <el-row style="margin-right: 20px">
          <el-col :span="8">
            <el-form-item label="字典组" class="width100">
              <el-input v-model="stmDict.cnDictValName" :disabled="true"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="字典组编码" class="width100">
              <el-input v-model="stmDict.dictType" :disabled="true"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="代码" class="width100">
              <el-input v-model="stmDict.dictCode" :disabled="true"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <!--工具条-->
        <search-bar more-display>
          <el-row>
            <el-col :span="8">
              <el-form-item label="字典组">
                <el-input
                          v-model="searchDetailCondition.LIKE_cnDictValname" placeholder="请输入字典组"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="描述">
                <el-input
                          v-model="searchDetailCondition.LIKE_remark" placeholder="请输入描述"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="字典值">
                <el-input
                          v-model="searchDetailCondition.EQ_dictVal" placeholder="请输入字典值"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </search-bar>

        <!-- 操作 -->
        <el-col :span="24" style="margin-bottom: 10px">
          <el-button type="primary" @click="handleAddDetail">新增</el-button>
          <el-button type="primary" @click="myResetDetail" style="float: right">重置</el-button>
          <el-button type="primary" @click="searchStmDictDetail" style="float: right">查询</el-button>
        </el-col>

        <!--数字字典详情列表-->
        <el-table :data="DetailTableData" highlight-current-row border @sort-change="sortChange1"
                  @selection-change="selsChange1" v-loading="listLoading1" style="width: 100%;">
          <el-table-column type="index" label="序号" width="50" align="center">
          </el-table-column>
          <el-table-column prop="cnDictValname" width="200" label="字典项"  header-align="center">
          </el-table-column>
          <el-table-column prop="dictVal" label="字典值" width="100" align="center">
          </el-table-column>
          <el-table-column prop="dictCode" label="代码" width="100" align="center">
          </el-table-column>
          <el-table-column prop="sort" label="排序" width="50" align="center">
          </el-table-column>
          <el-table-column show-overflow-tooltip prop="remark" min-width="100" label="描述" header-align="center" >

          </el-table-column>

          <el-table-column label="操作" width="250" align="center">

            <template slot-scope="scope">
              <el-button type="success" v-if="scope.row.enabled===0"
                         @click="handleStart(scope.$index, scope.row)">启用

              </el-button>
              <el-button type="warning" v-if="scope.row.enabled===1"
                         @click="handleStop(scope.$index, scope.row)">停用

              </el-button>
              <el-button  type="primary" @click="getEditDetailBYId(scope.$index, scope.row)">编辑
              </el-button>
              <el-button type="danger"  @click="handleDelDetail(scope.$index, scope.row)">删除</el-button>
            </template>

          </el-table-column>
        </el-table>

        <!--工具条-->
        <el-row>
          <el-col :span="24" class="toolbar">
            <el-pagination
              :current-page="currentPage1"
              :page-size="pageSize1"
              @size-change="handleSizeChange1"
              @current-change="handleCurrentChange1"
              layout="total,sizes,prev, pager, next, jumper"
              :total="total1" style="float: right">
            </el-pagination>
          </el-col>
        </el-row>
      </el-form>

    </el-dialog>
    <!--新增数字字典详情 弹窗 -->
    <el-dialog :title="dialogDeatilTitle" size="tiny" :visible.sync="stmDictDetailVisible2" :close-on-click-modal="false">
      <el-form :model="stmDictDetail" :rules="rules1" label-width="110px" ref="stmDictDetail">
        <el-row class="f-mt10 f-mb10">
          <el-col :span="24">
            <el-form-item label="字典项" class="width70" prop="cnDictValname">
              <el-input v-model="stmDictDetail.cnDictValname" placeholder="请输入字典项"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row class="f-mt10 f-mb10">
          <el-col :span="24">
            <el-form-item label="字典值" class="width70" prop="dictVal"
                          :rules="[{required: true,type:'number', message: '请输入字典值', trigger: 'change'}]">
              <el-input type="number" v-model.number="stmDictDetail.dictVal" placeholder="请输入字典值"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row class="f-mt10 f-mb10">
          <el-col :span="24">
            <el-form-item label="排序" class="width70" prop="sort"
                          :rules="[{required: true,type:'number', message: '请输入排序', trigger: 'change'}]">
              <el-input type="number" v-model.number="stmDictDetail.sort" placeholder="请输入排序"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row class="f-mt10 f-mb10">
          <el-col :span="24">
            <el-form-item label="描述" prop="remark">
              <el-input type="textarea" v-model="stmDictDetail.remark" placeholder="请输入描述"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="stmDictDetailVisible2 = false">取消</el-button>
        <el-button type="primary" @click.native="saveStmDictDetail" :loading="submitLoading2">提交</el-button>
      </div>
    </el-dialog>

  </section>
</template>

<script>
import {objToFilter, resetObjNull} from '../../lib/util';
import {
  searchDictList,
  saveStmDict,
  deleteStmDict,
  searchDictListDetail,
  saveStmDictDetail,
  deleteStmDictDetail,
  batchStart
} from '../../api/v3/stmDict.js';
export default {
  data () {
    return {
      currendDictCode: '', // 当前的数字字典
      searchCondition: {
        LIKE_cnDictValName: null,
        LIKE_dictType: null,
        EQ_dictCode: null
      },
      searchDetailCondition: {
        LIKE_cnDictValname: null,
        EQ_dictVal: null,
        LIKE_remark: null
      },

      dialogTitle: '新增',
      addDialogTitle: '新增',
      dialogDeatilTitle: '新增',
      condition: {
        name: '',
        number: ''
      },
      sels: [],
      tableData: [],
      total: 0,
      currentPage: 1,
      pageSize: 10,
      sortProp: null,
      sortOrder: 'ascending',
      listLoading: false,
      sels1: [],
      DetailTableData: [],
      total1: 0,
      currentPage1: 1,
      pageSize1: 10,
      sortProp1: null,
      sortOrder1: 'ascending',
      listLoading1: false,
      // 详情
      stmDictVisible: false,
      stmDictDetailVisible: false,
      stmDictDetailVisible2: false,
      submitLoading: false,
      submitLoading2: false,
      // 数字字典表单数据
      stmDict: {
        'id': null,
        'dictType': null,
        'addressId': null,
        dictCode: '',
        'cnDictValName': null,
        sort: '',
        'remark': null
      },
      // 数字字典表单数据
      stmDictDetail: {
        'id': null,
        'dictCode': null,
        'dictVal': null,
        'cnDictValname': null,
        'enabled': null,
        sort: '',
        'remark': null
      },
      // 数字字典验证规则
      rules: {
        cnDictValName: [
          {required: true, message: '请输入字典组', trigger: 'blur'},
          {min: 2, max: 60, message: '长度在2到 60 个字符', trigger: 'blur'}
        ],
        dictType: [
          {required: true, message: '请输入字典组编码', trigger: 'blur'},
          {min: 2, max: 60, message: '长度在2到 60 个字符', trigger: 'blur'}
        ]
      },
      //        // 数字字典详情验证规则
      rules1: {
        cnDictValname: [
          {required: true, message: '请输入字典项', trigger: 'blur'},
          {min: 2, max: 60, message: '长度在2到 60 个字符', trigger: 'blur'}
        ],
        remark: [
          {min: 2, max: 60, message: '长度在2到 60 个字符', trigger: 'blur'}
        ]
      }

    };
  },
  methods: {
    // 单 条启用
    handleStart (index, row) {
      this.$confirm('确认启用该数字字典详情吗?', '提示', {
        type: 'warning'
      }).then(() => {
        this.listLoading1 = true;
        let enabled = 1;
        batchStart(row.id, enabled).then((res) => {
          this.listLoading1 = false;
          this.$message({
            message: '启用成功！',
            type: 'success'
          });
          this.getDetailTableData();
        });
      }).catch(() => {
      });
    },
    // 单 条停用
    handleStop (index, row) {
      this.$confirm('确认停用该数字字典详情吗?', '提示', {
        type: 'warning'
      }).then(() => {
        this.listLoading1 = true;
        let enabled = 0;
        batchStart(row.id, enabled).then((res) => {
          this.listLoading1 = false;
          this.$message({
            message: '停用成功！',
            type: 'success'
          });
          this.getDetailTableData();
        });
      }).catch(() => {
      });
    },

    // 数字字典新增数据提交
    handleSubmit () {
      // 数字字典表单验证
      this.$refs['stmDict'].validate((valid) => {
        if (valid) {
          this.submitLoading = true;
          saveStmDict(this.stmDict).then((res) => {
            this.submitLoading = false;
            if (res.data) {
              this.stmDictVisible = false;
              this.getTableData();
              this.$message.success('保存/修改成功！');
            }
          }).catch(function (error) {
            console.log(error);
          });
        } else {
          return false;
        }
      });
    },
    // 数字字典详情新增数据提交
    saveStmDictDetail () {
      this.stmDictDetail.dictCode = this.currendDictCode;
      // 数字字典详情表单验证
      this.$refs['stmDictDetail'].validate((valid) => {
        if (valid) {
          this.submitLoading2 = true;
          if (this.stmDictDetail.id === null) {
            this.stmDictDetail.enabled = 1;
          }
          saveStmDictDetail(this.stmDictDetail).then((res) => {
            this.submitLoading2 = false;
            if (res.data) {
              this.stmDictDetailVisible2 = false;
              this.getDetailTableData();
              this.submitLoading2 = false;
              this.$message.success('保存/修改成功！');
            }
          }).catch(function (error) {
            console.log(error);
          });
        } else {
          return false;
        }
      });
    },
    //      // 数字字黄 搜索 栏重置
    myReset () {
      resetObjNull(this.searchCondition);
    },
    // 数字字典详情 搜索 栏重置
    myResetDetail () {
      resetObjNull(this.searchDetailCondition);
    },
    //
    loadingLists (filter) {
      this.listLoading = true;
      searchDictList({
        filters: filter,
        size: this.pageSize,
        page: this.currentPage - 1,
        sorts: (this.sortProp === null ? '' : this.sortProp + (this.sortOrder === 'ascending' ? ',desc' : ',asc'))
      }).then(res => {
        if (res.data) {
          this.tableData = res.data;
          this.total = Number(res.headers['x-total-count']);
          this.listLoading = false;
        }
      });
    },

    loadingLists1 (filter) {
      this.listLoading1 = true;
      searchDictListDetail({
        filters: filter + ';EQ_dictCode=' + this.currendDictCode,
        sort: '',
        page: this.currentPage1 - 1,
        size: this.pageSize1
      }).then((res) => {
        if (res.data) {
          this.DetailTableData = res.data;
          this.total1 = Number(res.headers['x-total-count']);
          this.listLoading1 = false;
        }
      });
    },
    getDetailTableData () {
      this.listLoading1 = true;
      searchDictListDetail({
        filters: 'EQ_dictCode=' + this.currendDictCode,
        sorts: '',
        page: this.currentPage1 - 1,
        size: this.pageSize1
      }).then((res) => {
        if (res.data) {
          this.DetailTableData = res.data;
          this.total1 = Number(res.headers['x-total-count']);
          this.listLoading1 = false;
        } else {
          this.$message.error(res.data.errorMsg);
        }
      });
    },
    //      // 数字字黄搜索栏搜索
    searchStmDict () {
      this.loadingLists(objToFilter(this.searchCondition));
    },
    searchStmDictDetail () {
      this.loadingLists1(objToFilter(this.searchDetailCondition));
    },
    //      // 数字字典新增弹出添加窗体
    handleAdd () {
      this.dialogTitle = '新增';
      this.resetForm();
      this.stmDictVisible = true;
    },
    // 数字字典详情新增弹出添加窗体
    handleAddDetail () {
      this.dialogDeatilTitle = '新增';
      this.resetDetailForm();
      this.stmDictDetailVisible2 = true;
    },
    // 打开数字字典编辑界面
    getEditBYId (index, row) {
      this.resetForm();
      this.stmDict = Object.assign({}, row);
      this.EditTitle = '修改';
      this.stmDictVisible = true;
    },
    // 打开数字字典详情编辑界面
    getEditDetailBYId (index, row) {
      this.resetDetailForm();
      this.stmDictDetail = Object.assign({}, row);
      this.dialogDeatilTitle = '修改';
      this.stmDictDetailVisible2 = true;
    },
    // 打开数字字典查看详情辑界面
    getEditDetail (index, row) {
      this.currendDictCode = row.dictCode;
      this.stmDict = Object.assign({}, row);
      this.addDialogTitle = '查看详情';
      this.listLoading1 = true;
      searchDictListDetail({
        filters: 'EQ_dictCode=' + row.dictCode,
        sorts: '',
        page: this.currentPage1 - 1,
        size: this.pageSize1
      }).then((res) => {
        if (res.data) {
          this.DetailTableData = res.data;
          this.total1 = Number(res.headers['x-total-count']);
          this.listLoading1 = false;
        }
      });
      this.stmDictDetailVisible = true;
    },
    //      // 重置数字字典表单
    resetForm () {
      if (this.$refs.stmDict) {
        this.$refs.stmDict.resetFields();
      }
      // 当先点击修改，再点击新增，会出现值没有清空,修复处理
      for (let p in this.stmDict) {
        if (this.stmDict[p] instanceof Array) {
          this.stmDict[p] = [];
        } else {
          this.stmDict[p] = null;
        }
      }
    },
    //      // 重置数字字典详情表单
    resetDetailForm () {
      if (this.$refs.stmDictDetail) {
        this.$refs.stmDictDetail.resetFields();
      }
      // 当先点击修改，再点击新增，会出现值没有清空,修复处理
      for (let p in this.stmDictDetail) {
        if (this.stmDictDetail[p] instanceof Array) {
          this.stmDictDetail[p] = [];
        } else {
          this.stmDictDetail[p] = null;
        }
      }
    },
    //
    //      // 数字字典删除单条数据操作
    handleDel (index, row) {
      this.$confirm('确认删除该数字字典吗?', '提示', {
        type: 'warning'
      }).then(() => {
        this.listLoading = true;
        deleteStmDict(row.id).then((res) => {
          this.listLoading = false;
          this.$message({
            message: '删除成功！',
            type: 'success'
          });
          this.currentPage = 1;
          this.searchStmDict();
        });
      }).catch(() => {
      });
    },
    // 数字字典详情删除单条数据操作
    handleDelDetail (index, row) {
      this.$confirm('确认删除该数字字典详情吗?', '提示', {
        type: 'warning'
      }).then(() => {
        this.listLoading = true;
        deleteStmDictDetail(row.id).then((res) => {
          this.listLoading = false;
          this.$message({
            message: '删除成功！',
            type: 'success'
          });
          this.currentPage1 = 1;
          this.searchStmDictDetail();
        });
      }).catch(() => {
      });
    },

    // 多选操作
    selsChange (sels) {
      this.sels = sels;
    },
    // 排序操作
    sortChange (o) {
      this.sortProp = o.prop;
      this.sortOrder = o.order;
      this.searchStmDict();
    },
    // 每页几条操作
    handleSizeChange (val) {
      this.pageSize = val;
      this.searchStmDict();
    },
    // 第几页操作
    handleCurrentChange (val) {
      this.currentPage = val;
      this.searchStmDict();
    },

    // 多选操作
    selsChange1 (sels) {
      this.sels1 = sels;
    },
    // 排序操作
    sortChange1 (o) {
      this.sortProp1 = o.prop;
      this.sortOrder1 = o.order;
      this.searchStmDictDetail();
    },
    // 每页几条操作
    handleSizeChange1 (val) {
      this.pageSize = val;
      this.searchStmDictDetail();
    },
    // 第几页操作
    handleCurrentChange1 (val) {
      this.currentPage1 = val;
      this.searchStmDictDetail();
    },
    // 获取数字字典借 列表
    getTableData () {
      this.listLoading = true;
      searchDictList({
        filters: '',
        sort: '',
        page: this.currentPage - 1,
        size: this.pageSize
      }).then((res) => {
        if (res.data) {
          this.tableData = res.data;
          this.total = Number(res.headers['x-total-count']);
          this.listLoading = false;
        }
      });
    }
  },
  mounted () {
    this.getTableData();
    this.$store.commit('initDict');
  }
};
</script>

<style lang="less">

</style>
